{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d1bc473d",
   "metadata": {},
   "source": [
    "------------\n",
    "* 2022/10/17/week 09\n",
    "* Python学习记录\n",
    "* 记录人：wu-huichun\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6155f477",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1.用户输入\n",
    "\n",
    "> 2.文本格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57194639",
   "metadata": {},
   "source": [
    "## 1.用户输入\n",
    "\n",
    "* input 方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "34e9a703",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：13456\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统\n",
    "username = input(\"账号：\")\n",
    "passward = input(\"密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4316658d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "13456\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(passward)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f1136632",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登录成功，欢迎~admin\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代1 增加判断\n",
    "\n",
    "user01 = \"admin\"\n",
    "passward01 = \"123456\"\n",
    "\n",
    "username = input(\"账号：\")\n",
    "passward = input(\"密码：\")\n",
    "# 情景一：账号密码都正确\n",
    "if user01 == username and passward01 == passward:\n",
    "    print(\"登录成功，欢迎~\"+user01)\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "        print(\"登录失败，账号不存在或密码不正确！请重新输入！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "fa6c573f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登录成功，欢迎~admin\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环for+range()\n",
    "\n",
    "user01 = \"admin\"\n",
    "passward01 = \"123456\"\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    passward = input(\"密码：\")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and passward01 == passward:\n",
    "        print(\"登录成功，欢迎~\"+user01)\n",
    "        break # 中止循环\n",
    "    # 情景二：账号不存在或密码不正确，用户有三次机会，输入三次之后，1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确!请重新输入！您还有\"+str(i-1)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1个小时后再来尝试\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8c5c589",
   "metadata": {},
   "source": [
    "## 2.字符串的格式化输出\n",
    "\n",
    "> 1.字符串的拼接 +\n",
    "\n",
    "> 2.占位符 %s\n",
    "\n",
    "> 3.格式化输出的方法： .format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cac23a8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：深圳\n",
      "工作：产品经理助理\n",
      "年龄：22\n",
      "期待薪资：1W/月\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''-------INFO '''+ name + '''-------\n",
    "地区：'''+ region + '''\n",
    "工作：'''+ job + '''\n",
    "年龄：'''+ age + '''\n",
    "期待薪资：'''+ salary\n",
    "# 麻烦，容易出错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "25bf8b02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------INFO 李华-------\n",
      "地区：深圳--------\n",
      "工作：产品经理助理\n",
      "年龄：22\n",
      "期待薪资：1W/月\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "49f41abd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：深圳\n",
      "工作：前端开发\n",
      "年龄：22\n",
      "期待薪资：1w1/月\n",
      "-------INFO 李华-------\n",
      "地区：深圳\n",
      "工作：前端开发\n",
      "年龄：22\n",
      "期待薪资：1w1/月 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） 占位符 %s\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''-------INFO %s-------\n",
    "地区：%s\n",
    "工作：%s\n",
    "年龄：%s\n",
    "期待薪资：%s '''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d53b10f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：李华\n",
      "地区：深圳\n",
      "工作：python web开发\n",
      "年龄：22\n",
      "期待薪资：1w8/月\n",
      "-------INFO 李华-------\n",
      "地区：深圳\n",
      "工作：python web开发\n",
      "年龄：22\n",
      "期待薪资：1w8/月 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） .format() 不考虑顺序，只考虑一一对应关系\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''-------INFO {昵称}-------\n",
    "地区：{地区}\n",
    "工作：{工作职位}\n",
    "年龄：{年龄}\n",
    "期待薪资：{薪资} '''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "# 书写规范，字符串中的字段一一对应，不考虑其顺序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "479be677",
   "metadata": {},
   "source": [
    "## 课后作业：\n",
    "\n",
    "> 1.第二章P93 前所有项目练习（下周讲）\n",
    "\n",
    "> 2.购物车项目\n",
    "\n",
    ">> 要求：\n",
    ">>> 1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    ">>> 2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    ">>> 3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    ">>> 4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "\n",
    " * 获取用户输入金额\n",
    " \n",
    " * 打印商品给用户\n",
    " \n",
    " * 让用户输入商品编号进行商品的购买（列表的值，列表的索引值）\n",
    " \n",
    " * 检查用户的余额是否足够，用+计算商品的金额，用if条件判断。如果够，则结束，如果不够，则让用户充钱，再进行购买\n",
    " \n",
    " * 结算/退出时，打印账单给用户，并告诉用户的余额是多少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80d38bc5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
